<?php
/*
	[DESTOON B2B System] Copyright (c) 2008-2018 www.destoon.com
	This is NOT a freeware, use is subject to license.txt
*/
require 'common.inc.php';
$username = $domain = '';
if(isset($homepage) && check_name($homepage)) {
	$username = $homepage;
} else if(!$cityid) {
	$host = get_env('host');
	if(substr($host, 0, 4) == 'www.') {
		$whost = $host;
		$host = substr($host, 4);
	} else {
		$whost = $host;
	}
	if($host && strpos(DT_PATH, $host) === false) {
		if(substr($host, -strlen($CFG['com_domain'])) == $CFG['com_domain']) {
			$www = substr($host, 0, -strlen($CFG['com_domain']));
			if(check_name($www)) {
				$username = $homepage = $www;
			} else {
				include load('company.lang');
				$head_title = $L['not_company'];
				if($DT_BOT) dhttp(404, $DT_BOT);
				include template('com-notfound', 'message');
				exit;
			}
		} else {
			if($whost == $host) {//301 xxx.com to www.xxx.com
				$w3 = 'www.'.$host;
				$c = $db->get_one("SELECT userid FROM {$DT_PRE}company WHERE domain='$w3'");
				if($c) d301('http://'.$w3);
			}
			$c = $db->get_one("SELECT username,domain FROM {$DT_PRE}company WHERE domain='$whost'".($host == $whost ? '' : " OR domain='$host'"), 'CACHE');
			if($c) {
				$username = $homepage = $c['username'];
				$domain = $c['domain'];
			}
		}
	}
}
if($username) {
	$moduleid = 4;
	$module = 'company';
	$MOD = cache_read('module-'.$moduleid.'.php');
	include load('company.lang');
	require DT_ROOT.'/module/'.$module.'/common.inc.php';
	include DT_ROOT.'/module/'.$module.'/init.inc.php';
} else {
	if($DT['safe_domain']) {
		$safe_domain = explode('|', $DT['safe_domain']);
		$pass_domain = false;
		foreach($safe_domain as $v) {
			if(strpos($DT_URL, $v) !== false) { $pass_domain = true; break; }
		}
		$pass_domain or dhttp(404);
	}
	if($DT['index_html']) {
		$html_file = $CFG['com_dir'] ? DT_ROOT.'/'.$DT['index'].'.'.$DT['file_ext'] : DT_CACHE.'/index.inc.html';
		if(!is_file($html_file)) tohtml('index');		
		if(is_file($html_file)) exit(include($html_file));
	}
	$AREA or $AREA = cache_read('area.php');
	if($EXT['mobile_enable']) $head_mobile = DT_MOB;
	$index = 1;
	$seo_title = $DT['seo_title'];
	$head_keywords = $DT['seo_keywords'];
	$head_description = $DT['seo_description'];
	$CSS = array('index');
	
	
	//商城产品列表
	$mall_result = $db->query("SELECT * FROM `ds_mall_16` WHERE `thumb` <> ''  AND status = 3 AND level = 1 ORDER BY itemid DESC LIMIT 10");
	while($r = $db->fetch_array($mall_result)) {
		$mall_list[] = $r;
	}
	//公司企业列表
	$company_result = $db->query("SELECT * FROM `ds_company` WHERE `thumb` <> '' AND level = 1 ORDER BY userid DESC LIMIT 12");
	while($r = $db->fetch_array($company_result)) {
		$company_list[] = $r;
	}
	//行业人物列表
	$renwu_result = $db->query("SELECT * FROM `ds_article_23` WHERE `thumb` <> '' AND status = 3 ORDER BY itemid DESC LIMIT 3");
	while($r = $db->fetch_array($renwu_result)) {
		$renwu_list[] = $r;
	}
	//智能展会列表
	$zhan_result = $db->query("SELECT * FROM `ds_exhibit_8` WHERE `thumb` <> '' AND status = 3 AND level = 1 ORDER BY itemid DESC LIMIT 4");
	while($r = $db->fetch_array($zhan_result)) {
		$zhan_list[] = $r;
	}
	//咨询列表
	$zx_result = $db->query("SELECT * FROM `ds_article_21` WHERE status = 3 ORDER BY itemid DESC LIMIT 16");
	while($r = $db->fetch_array($zx_result)) {
		$zx_list[] = $r;
	}
	//问答列表
	$wd_result = $db->query("SELECT dk.addtime,dk.username,dk.linkurl,dk.title,ka.username AS a_name,ka.addtime AS u_addtime,ka.content FROM `ds_know_10` dk JOIN ds_know_answer_10 ka ON ka.itemid = dk.aid WHERE dk.process = 3 AND dk.status = 3 ORDER BY dk.itemid DESC LIMIT 5");
	while($r = $db->fetch_array($wd_result)) {
		$wd_list[] = $r;
	}
	//智能专题
	$zt_result = $db->query("SELECT * FROM `ds_special_11` WHERE `thumb` <> '' AND status = 3 ORDER BY itemid DESC LIMIT 4");
	while($r = $db->fetch_array($zt_result)) {
		$zt_list[] = $r;
	}
	//公告列表
	$announce_result = $db->query("SELECT * FROM `ds_announce` ORDER BY itemid DESC LIMIT 10");
	while($r = $db->fetch_array($announce_result)) {
		$announce_list[] = $r;
	}
	
	//统计
	$count_data = array();
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_mall_16`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['mall'] = $r['total'];
	}
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_company`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['company'] = $r['total'];
	}
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_exhibit_8`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['exhibit'] = $r['total'];
	}
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_know_10`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['know'] = $r['total'];
	}
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_info_26`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['fn'] = $r['total'];
	}
	$count_result = $db->query("SELECT count(*) AS total FROM `ds_buy_24`");
	while($r = $db->fetch_array($count_result)) {
		$count_data['buy'] = $r['total'];
	}
	
	$data_result = $db->query("SELECT * FROM `ds_photo_12` where level = 9 order by itemid desc limit 4");
	while($r = $db->fetch_array($data_result)) {
		$resut_img[] = array("pic" => $r['thumb'] , 'title' => $r['title'] ,'link' => $r['linkurl']);
	}
	
	
	if($city_template) {
		include template($city_template, 'city');
	} else {		
		include template('index');
	}
}
?>